package com.gxuwz.Market.business.service;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gxuwz.Market.business.dao.ServiceFormDAO;
import com.gxuwz.Market.business.entity.ServiceForm;
import com.gxuwz.Market.business.entity.TemplateUpload;
import com.gxuwz.core.pagination.Result;
import com.gxuwz.core.util.UidUtils;

@Service("serviceFormService")
public class ServiceFormImpl implements IServiceFormService {
	@Autowired
	private ServiceFormDAO serviceFormDAO;

	@Override
	public ServiceForm findById(int id) {
		// TODO Auto-generated method stub
		return serviceFormDAO.findById(id);
	}

	@Override
	public List<ServiceForm> findAll() {
		// TODO Auto-generated method stub
		return serviceFormDAO.findAll();
	}

	@Override
	public Result<ServiceForm> find(ServiceForm serviceForm, int page, int size) {
		// TODO Auto-generated method stub
		return serviceFormDAO.find(serviceForm, page, size);
	}

	@Override
	public List<ServiceForm> findByProperty(String property, String value) {
		// TODO Auto-generated method stub
		return serviceFormDAO.findByProperty(property, value);
	}

	@Override
	public void add(ServiceForm serviceForm) {
		// TODO Auto-generated method stub
		serviceFormDAO.save(serviceForm);

	}

	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub
		ServiceForm serviceForm = serviceFormDAO.findById(id);
		serviceForm.setIsDelete(1);
		serviceFormDAO.update(serviceForm);

	}

	@Override
	public void update(ServiceForm serviceForm) {
//		if(serviceForm.getFormState() == 1){
//			ServiceForm sf = serviceFormDAO.findById(serviceForm.getId());
//			sf.setIsDelete(1);
//			serviceFormDAO.update(sf);
//			serviceForm.setId(null);
//			serviceForm.setFormId(UidUtils.UID());
//			serviceForm.setFormState(0);
//			serviceFormDAO.save(serviceForm);
//		}else{
//			serviceFormDAO.update(serviceForm);
//		}
		serviceFormDAO.update(serviceForm);

	}

	/**
	 * 通过文件的Id查找文件
	 * @return
	 * @author 黄森南
	 * @throws FileNotFoundException 
	 * @throws IOException 
	 * @date 2018.01.27
	 */
	public TemplateUpload findByFid(Integer fileId) {
		return serviceFormDAO.findByFid( fileId);
		// TODO Auto-generated method stub
		
	}

}
